//
//  YZMPageControl.m
//  YZMicroStock
//
//  Created by wangminhong on 16/3/22.
//  Copyright © 2016年 cqjr. All rights reserved.
//

#import "YZMPageControl.h"
#import <ColorUtils/ColorUtils.h>

@implementation YZMPageControl

@synthesize normalColor = _normalColor;
@synthesize highlightColor = _highlightColor;

- (id)init{
    
    self = [super init];
    
    if (self) {
        
        self.normalColor = [UIColor colorWithString:@"FFFFFF1E"];
        self.highlightColor = [UIColor colorWithString:@"#FFFFFF"];
    }
    
    return self;
}

// 设置正常状态点按钮的颜色
- (void)setNormalColor:(UIColor *)normalColor{
    
    _normalColor = normalColor;
    [self updateDots];
}

// 设置高亮状态点按钮的颜色
- (void)setHighlightColor:(UIColor *)highlightColor{
    
    _highlightColor = highlightColor;
    [self updateDots];
}

// 捕捉点击事件
- (void)endTrackingWithTouch : (UITouch *)touch withEvent:(UIEvent *)event
{
    [super endTrackingWithTouch:touch withEvent:event];
    [self updateDots];
}

// 更新显示所有的点按钮
- (void)updateDots
{
    NSArray *subview = self.subviews;  // 获取所有子视图
    for(NSInteger i =0; i<[subview count]; i++)
    {
        UIView *dot = [subview objectAtIndex:i];
        dot.backgroundColor = self.currentPage == i?_highlightColor:_normalColor;
    }
}

- (void)dealloc
{
    _normalColor = nil;
    _highlightColor = nil;
}

- (void)setCurrentPage:(NSInteger)currentPage{
    
    [super setCurrentPage:currentPage];
    [self updateDots];
}

@end
